const mockSwitch = false;
/**
 * 是否为自己的回合
 * 双方未准备之前不能落子
 */
let selfTurn = false;

/**
 * 是否准备
 */
let already = false;

let blackScore = 0;

let whiteScore = 0;

let firstPlayer = 0;

/**
 * 先手玩家的棋子颜色
 */
let firstPlayerColor = '';

window.onload = function () {
    /**
     * 登录检测
     */
    let userName = ZhhSessionStorage_getItem('userName');
    if (!userName) {
        // window.location.href = "/zhh/view/login";
    }
    /**
     * 主加载JS，如果有其他配置类型JS需要在它前面引入
     */
    document.getElementById("sendMessageButton").addEventListener("click", sendMessageEvent);

    document.getElementById('messageInput').addEventListener('keydown', function (event) {
        if (event.key === 'Enter') {
            event.preventDefault(); // 阻止默认的表单提交行为（如果有）
            document.getElementById('sendMessageButton').click(); // 触发按钮点击事件
        }
    });

    // 复制房间码
    document.getElementById('roomInformationClick').addEventListener('click', function () {
        let roomCode = ZhhSessionStorage_getItem('roomCode');
        if (roomCode) {
            copyToClipboard(roomCode);
        }
    })

    document.getElementById('logout-button').addEventListener('click', function () {
        ZhhSessionStorage_clear();
        popUpMessageShow('退出房间');
        setTimeout(() => {
            window.location.href = "/zhh/view/index";
        }, 1000);
    });

    // 初始化绘制棋盘
    drawChessboard(boardSize, gridSize);
    ChessBoardData_init(boardSize, boardSize);
    initializeTheDisplayContent();
    let roomCode = ZhhSessionStorage_getItem('roomCode');
    if (roomCode) {
        refreshRoomDetail(roomCode);
    }

    if (mockSwitch) {

        let mockChess = [];
        for (let i = 0; i < boardSize; i++) {
            mockChess.push(new Array(boardSize));
            for (let j = 0; j < boardSize; j++) {
                mockChess[i][j] = Math.floor(Math.random() * 3);
            }
        }
        fillChess(mockChess);
        ChessBoardData_fillData(mockChess);
        setFirstPlay(1);
        currentTurnTo(2);
        addReadyButton();

        for (let i = 1; i <= 5; i++) {
            addMessageContent(i % 2 === 0, `消息测试${i}`, `玩家${i}`, i % 3);
        }
    }
}



